package structure.stack;

import java.util.Scanner;

/**
* @description: 单链表实现栈测试
* @author: wangjun
* @create: 2022-04-22
*/
public class StackByLinkedListMain {

    public static void main(String[] args) {
        System.out.println("单链表实现栈测试：");
        StackByLinkedList stack = new StackByLinkedList(3);
        Scanner sc = new Scanner(System.in);
        while (true){
            switch (sc.next()){
                case "show":
                    stack.show();
                    break;
                case "pop":
                    int pop = stack.pop();
                    if(pop == -1){
                        System.out.println("栈空");
                    }else{
                        System.out.println("弹出元素："+pop);
                    }
                    break;
                case "push":
                    stack.push(new StackNode(sc.nextInt()));
                    break;
                case "exit":
                    System.exit(0);
            }
        }
    }
}